{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "initial centroids are: [[1.91443901e+01 1.19880000e-03 3.17640000e-03 2.25786000e-02\n",
      "  5.42695995e+00 6.96960000e-02 3.07094400e+01 1.14288000e-02\n",
      "  4.40235455e+01]\n",
      " [2.60868530e+01 3.59640000e-01 6.82926000e+00 4.10520000e-02\n",
      "  3.75667740e+00 3.87200000e-02 4.55400000e+00 8.00016000e+00\n",
      "  4.52029166e+01]\n",
      " [1.98661419e+01 0.00000000e+00 9.67213800e+00 5.29570800e+00\n",
      "  4.26223440e+00 1.85856000e-01 1.51680000e+01 4.85724000e-01\n",
      "  4.53232901e+01]\n",
      " [1.87788008e+01 4.37562000e-01 1.19273820e+01 3.42100000e-02\n",
      "  1.24522578e+01 2.16832000e-01 6.78600000e+00 6.70013400e+00\n",
      "  4.32476426e+01]]\n",
      "group result iteration 1 [496. 125. 220. 131.]\n",
      "group result iteration 2 [490. 126. 238. 118.]\n",
      "group result iteration 3 [482. 125. 249. 116.]\n",
      "group result iteration 4 [475. 126. 256. 115.]\n",
      "group result iteration 5 [463. 134. 269. 106.]\n",
      "group result iteration 6 [452. 133. 278. 109.]\n",
      "group result iteration 7 [445. 132. 283. 112.]\n",
      "group result iteration 8 [442. 132. 282. 116.]\n",
      "group result iteration 9 [440. 132. 279. 121.]\n",
      "group result iteration 10 [440. 132. 276. 124.]\n",
      "AFwkmeans Finish!\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAxD0lEQVR4nO3deZxU1Znw8d9DszR0I5tIkD0CClYhCEpAIiCKGHfUKFHHtY2jMSaOOjr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Vwc7W3acapLxGRVl67/7eBz4DFwD9602UjIoOl8QVQVgDjReRIr+N3GvBmE+L4BugYt78YuMX7QENERtTzvE64NQzKvbb6WA299vniLcd9YOA18fTFvW9jAEv8JrX8Cogf3fMELtmuBGrXhP36DJegFwE3ek0cT+KaOf7idYj+D43UfL3Vj+4GlgEfAH9R1aZMkbsMGBrr3AXuw32QfejFcF89z5sLjBKRVbhk/qkXTwmub+Lj2p3KwONAjoh8BPwOuNprEjMGsNk5jTEm61iN3xhjsowlfmOMyTKW+I0xJstY4jfGmCxjid8YY7KMJX5jjMkylviNMSbL/H9aUvbLmP7AjgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "****************************** model performance ******************************\n",
      "Homogeneity Score         (均一性):  0.7403232479927029\n",
      "Completeness Score        (完整性):  0.6948789439268747\n",
      "V-Measure Score           (V量):  0.7168816207584359\n",
      "Adjusted Rand Score       (调整后兰德指数):  0.7430473928717435\n",
      "Adjusted Mutual Info Score(调整后的共同信息):  0.7157842781881982\n",
      "Calinski Harabasz Score:  (方差比指数)  715.893651686806\n",
      "Silhouette Score          (轮廓分数):  0.6029499825578766\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "from AFwkmeans_class import *\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "AFwkmeans=AFwkmeans()\n",
    "\n",
    "orig_data = pd.read_excel('test4.xlsx')\n",
    "orig_data.dropna(inplace=True)\n",
    "\n",
    "x_orig_data = orig_data.drop('TRUE VALUE',axis=1)\n",
    "y_label = orig_data['TRUE VALUE']\n",
    "\n",
    "x_data=np.array(x_orig_data)\n",
    "\n",
    "n_iters = 10\n",
    "n_clusters = 4\n",
    "centroids = AFwkmeans.plus_plus(x_data, n_clusters)\n",
    "dist = np.zeros((x_data.shape[0],n_clusters), dtype=float)\n",
    "\n",
    "print(\"initial centroids are:\",centroids)\n",
    "\n",
    "w = np.ones((1,x_data.shape[1]), dtype=float)/x_data.shape[1]  # weight initialization\n",
    "tol=1e-7\n",
    "count=0\n",
    "C = np.zeros(n_iters)\n",
    "\n",
    "#AFwkmeans.__check_params(x_data, n_clusters, w, n_iters, tol)\n",
    "\n",
    "for i in range(n_iters):\n",
    "    count+=1\n",
    "    group= np.zeros(n_clusters)\n",
    "    old_centroids=centroids.copy()\n",
    "    for j in range(x_data.shape[0]):\n",
    "        distance = np.power(x_data[j,:]-centroids, 2)  \n",
    "        distance = np.sum(w*distance, axis=1)\n",
    "        distance = np.sqrt(distance) \n",
    "        dist[j,:] = distance\n",
    "    idx = np.argmin(dist, axis=1)   # predicted group index\n",
    "\n",
    "    for k in range(n_clusters):\n",
    "        d = x_data[idx==k, :]\n",
    "        group[k]=d.shape[0]\n",
    "        centroids[k,:] = np.mean(d, axis=0)\n",
    "\n",
    "#     adaptive feature weighted 自适应权重重新分配       \n",
    "    cc=np.zeros(d.shape[1])\n",
    "    for l in range(d.shape[1]):\n",
    "        ddn=0\n",
    "        meanl=np.mean(centroids[:,l])\n",
    "        ddm=np.power(centroids[:,l]-meanl, 2)\n",
    "        ddm=np.sum(ddm)\n",
    "        for k in range(n_clusters):\n",
    "            dd=x_data[idx==k, :]\n",
    "            dn=np.power(dd[:,l]-centroids[k,l], 2)\n",
    "            ddn=ddn+np.sum(dn)\n",
    "        cc[l]=ddm/ddn\n",
    "        \n",
    "    for n in range(d.shape[1]):\n",
    "        w[0,n]=cc[n]/sum(cc)\n",
    "            \n",
    "        \n",
    "        \n",
    "    print('group result iteration', count, group)   # group number after each iterration\n",
    "    centroid_change=AFwkmeans.sqrsum(centroids - old_centroids)\n",
    "    C[i]=centroid_change\n",
    "    if centroid_change <= tol:\n",
    "                break\n",
    "print(\"AFwkmeans Finish!\")\n",
    "\n",
    "plt.plot(np.arange(n_iters)+1, C, color='blue', marker='o', markersize=5, label='centroid distance change')\n",
    "plt.grid(True)\n",
    "plt.xlabel(\"Number of iteration\")\n",
    "plt.ylabel(\"centroid distance change\")\n",
    "plt.legend(loc='best')\n",
    "plt.show()\n",
    "\n",
    "print(AFwkmeans.get_marks(x_data, y_label, idx))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
